package com.yunfei.api.smrz;
import com.yunfei.api.smrz.bo.AppFileSimpleBo;
import com.yunfei.api.smrz.bo.ShenHeYiJianBo;
import com.yunfei.bo.hgtzz.HeGeTouZiZheRenZhengBo;
import com.yunfei.bo.hgtzz.HeGeTouZiZheRenZhengSaveParam;
import com.yunfei.bo.hgtzz.HeGeTouZiZheRenZhengUpdateParam;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.bo.smrz.HeGeTouZiZheRenZhengParamBo;
import com.yunfei.bo.smrz.IdCardBo;
import com.yunfei.bo.smrz.IdCardType;
import com.yunfei.bo.zytzz.ZhuanYeTouZiZheRenZhengResultBo;
import com.yunfei.enums.ResultStatus;
import com.yunfei.enums.ShiMingRenZhengStatus;
import com.yunfei.mapper.aiiidb.*;
import com.yunfei.mapper.crm.HeGeTouZiZheRenZhengFileMapper;
import com.yunfei.mapper.crm.TblobtSorageMapper;
import com.yunfei.service.ShiMingRenZhengService;
import com.yunfei.utils.procedure.HeGeTouZiZheRenZhengProcedure;
import com.yunfei.utils.procedure.ShiMingRenZhengProcedureReturnInfo;
import com.yunfei.utils.string.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 合格投资者认证接口
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@SuppressWarnings("ALL")
@Api(value = "私募购买流程投资者查看详情",tags = "私募购买流程投资者查看详情")
@RestController
@RequestMapping("/api/licaishi/simuYuYue/renZhengDetail")
public class SiMuYuYueRenZhengTouZiZheChaKanDetailApiController {
    @Autowired
    private ShiMingRenZhengMapper shiMingRenZhengMapper;
    @Autowired
    private HeGeTouZiZheRenZhengMapper heGeTouZiZheRenZhengMapper;
    @Autowired
    private ShenHeYiJianMapper shenHeYiJianMapper;
    @Autowired
    private Environment env;
    @Autowired
    private TblobtSorageMapper tblobtSorageMapper;
    @Autowired
    private HeGeTouZiZheRenZhengFileMapper heGeTouZiZheRenZhengFileMapper;
    @Autowired
    private ShiMingRenZhengService shiMingRenZhengService;
    @Autowired
    private SiMuYuYueTouZiZheRenZhengDetailMapper siMuYuYueTouZiZheRenZhengDetailMapper;
    @Autowired
    private ZhuanYeTouZiZheRenZhengMapper zhuanYeTouZiZheRenZhengMapper;

    //查询
    @GetMapping("/get")
    @ApiOperation(value = "查看详情",notes = "查看详情",position = 1,response = Object.class)
    @ResponseBody
    public Object edite(String reserveNo,String cCustNo){
        ResultModel resultModel=new ResultModel();
        try{
            Map<String,Object> resultMap=new HashMap<>();
            Map<String,Object> rzQueryMap=new HashMap<>();
            Map<String,Object> queryMap=new HashMap<>();
            rzQueryMap.put("cCustNo",cCustNo);
            rzQueryMap.put("reserveNo",reserveNo);
            String rzResult=siMuYuYueTouZiZheRenZhengDetailMapper.get(rzQueryMap);
            String rzFlg="";
            String lSerialNo="";
            if(!StringUtil.isNullOrEmpty(rzResult)){
                String resultArray[]=rzResult.split(";");
                if(resultArray.length>0){
                    rzFlg=resultArray[0];
                }
                if(resultArray.length>1){
                    lSerialNo=resultArray[1];
                }
            }
            queryMap.put("lSerialNo",lSerialNo);
           if(rzFlg.equals("合格投资者")){
               HeGeTouZiZheRenZhengBo result=heGeTouZiZheRenZhengMapper.edite(queryMap);//获取单个值
               resultMap.put("result",result);
               //获取审核意见
               Map<String,Object> shenHeQueryMap=new HashMap<>();
               shenHeQueryMap.put("lSerialno",lSerialNo);
               List<ShenHeYiJianBo> shenHeYiJianBoList=shenHeYiJianMapper.hgtzzShenHeYiJianlist(shenHeQueryMap);
               resultMap.put("shenHeYiJian",shenHeYiJianBoList);
               Map<String,Object> fileQueryMap=new HashMap<>();
               fileQueryMap.put("cCustNo",cCustNo);
               fileQueryMap.put("lSerialNo",lSerialNo);
               List<AppFileSimpleBo> fileList=heGeTouZiZheRenZhengMapper.getFileList(fileQueryMap);
               resultMap.put("resultFile",fileList);
               resultModel.setCode(ResultStatus.SUCCESS.getCode());
               resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
               resultModel.setData(resultMap);
           }
            if(rzFlg.equals("专业投资者")){
                Map<String,Object> userInfoMap=new HashMap<>();
                userInfoMap.put("cCustNo",cCustNo);
                List<AppFileSimpleBo> fileList=zhuanYeTouZiZheRenZhengMapper.getFileList(userInfoMap);
                resultMap.put("resultFile",fileList);
                IdCardBo cardBo= shiMingRenZhengMapper.getLookInfo(userInfoMap);
                HeGeTouZiZheRenZhengBo userInfo=new HeGeTouZiZheRenZhengBo();
                userInfo.setCardNo(cardBo.getCardNo());
                userInfo.setCardType(cardBo.getCardType());
                userInfo.setCustNo(cardBo.getcCustNo());
                userInfo.setUserName(cardBo.getUserName());
                userInfo.setMobile(cardBo.getMobile());
                userInfo.setlSerialNo(lSerialNo);
                Map<String,Object> renzhengInfoQueryMap=new HashMap<>();
                renzhengInfoQueryMap.put("lSerialno",lSerialNo);
                ZhuanYeTouZiZheRenZhengResultBo zhuanYeTouZiZheRenZhengBo=zhuanYeTouZiZheRenZhengMapper.getRenZhengInfo(renzhengInfoQueryMap);
                if(!StringUtil.isNullOrEmpty(zhuanYeTouZiZheRenZhengBo)){
                    userInfo.setcStatus(zhuanYeTouZiZheRenZhengBo.getcStatus());//审核状态，中文
                    userInfo.setZhengMingType(zhuanYeTouZiZheRenZhengBo.getZhengMingType());//证明类型
                    userInfo.setMoney(zhuanYeTouZiZheRenZhengBo.getMoney());//证明金额
                }

                resultMap.put("userInfo",userInfo);
                //获取审核意见
                Map<String,Object> shenHeQueryMap=new HashMap<>();
                if(StringUtil.isNullOrEmpty(lSerialNo)){
                    lSerialNo="";
                }
                shenHeQueryMap.put("lSerialno",lSerialNo);
                List<ShenHeYiJianBo> shenHeYiJianBoList=shenHeYiJianMapper.zytzzShenHeYiJianList(shenHeQueryMap);
                resultMap.put("shenHeYiJian",shenHeYiJianBoList);
                List<IdCardType> idCardTypeList=shiMingRenZhengMapper.getCardType(null);//证件类型
                List<IdCardType> zhengMingType=heGeTouZiZheRenZhengMapper.getZhengMingType(null);//证明类型
                resultMap.put("cardType",idCardTypeList);
                resultMap.put("zhengMingType",zhengMingType);
                resultModel.setCode(ResultStatus.SUCCESS.getCode());
                resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
                resultModel.setData(resultMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return resultModel;
    }

}
